import "package:flutter/material.dart";
import "package:myapp/_common/NestedTabBarView.dart";
import "package:myapp/_views/home/widget/animate/AnimateCard_2.dart";
import "package:myapp/_views/home/widget/animate/AnimateRank.dart";
import "package:myapp/_views/home/widget/animate/animate.class.dart";
import "./widget/animate/AnimateSwiper.dart";
import "./widget/animate/AnimateMenu.dart";
import "./widget/animate/AnimateVipBar.dart";
import "./widget/animate/AnimateWatching.dart";
import "./widget/animate/AnimateHot.dart";
import "./widget/animate/AnimateComingSoon.dart";

final List<AnimateHotItem> hotList = [
  AnimateHotItem(
    coverUrl: './images/1.jpg',
    title: '不时用俄语小声说真心话的领桌艾莉同学',
    subTitle: '俄语传情真真切切',
    partition: '番剧',
    type: '小说改',
    tag: '独播',
    tagType: "0",
    episodes: '2',
    status: '1',
    score: '9',
  ),
  AnimateHotItem(
    coverUrl: './images/3.jpg',
    title: '我的三体 第四季',
    subTitle: '280万追番',
    partition: '国创',
    type: '科幻',
    tag: '出品',
    tagType: "1",
    episodes: '2',
    status: '1',
    score: '8',
  ),
  AnimateHotItem(
    coverUrl: './images/1.jpg',
    title: '地下城里的人们',
    subTitle: '我在迷宫当管理员',
    partition: '番剧',
    type: '漫画改',
    tag: '独播',
    tagType: "0",
    episodes: '2',
    status: '1',
    score: '8',
  ),
  AnimateHotItem(
    coverUrl: './images/3.jpg',
    title: '罗小黑战记',
    subTitle: '730万追番',
    partition: '国创',
    type: '原创',
    tag: '独播',
    tagType: "0",
    episodes: '40',
    status: '1',
    score: '9.9',
  ),
  AnimateHotItem(
    coverUrl: './images/1.jpg',
    title: '亚托莉-我挚爱的时光-',
    subTitle: '暗流涌动的海边日常',
    partition: '番剧',
    type: '游戏改',
    tag: '出品',
    tagType: "1",
    episodes: '1',
    status: '1',
    score: '8',
  ),
  AnimateHotItem(
    coverUrl: './images/3.jpg',
    title: '百变的七仓同学',
    subTitle: '独属一人的戏精女王',
    partition: '番剧',
    type: '漫画改',
    tag: '出品',
    tagType: "1",
    episodes: '2',
    status: '1',
    score: '8',
  ),
];

final List<List<dynamic>> list = [
  [
    AnimateHotItem(
      coverUrl: './images/2.jpg',
      title: '一起一起这里那里',
      subTitle: '站内高分番剧',
      partition: '番剧',
      type: '萌系',
      describe: '爱上了对我温柔以待的你',
      score: '9.8',
      episodes: '4',
      status: '1',
      tag: '',
    ),
    AnimateHotItem(
      coverUrl: './images/1.jpg',
      title: '迷宫饭',
      subTitle: '站内高分番剧',
      partition: '番剧',
      type: '漫画改',
      tag: '独播',
      tagType: "0",
      episodes: '24',
      status: '2',
      score: '9.8',
    ),
    AnimateHotItem(
      coverUrl: './images/3.jpg',
      title: '老夫老妻重返青春',
      subTitle: '站内高分番剧',
      partition: '番剧',
      type: '漫画改',
      tag: '独播',
      tagType: "1",
      episodes: '11',
      status: '2',
      score: '9.8',
    ),
    AnimateHotItem(
      coverUrl: './images/1.jpg',
      title: 'NO GAME NO LIFE 游戏人生',
      subTitle: '站内高分番剧',
      partition: '番剧',
      type: '奇幻',
      tag: '会员',
      tagType: "3",
      episodes: '12',
      status: '2',
      score: '9.8',
    ),
    AnimateHotItem(
      coverUrl: './images/3.jpg',
      title: '某科学的超电磁炮',
      subTitle: '镇站之番',
      partition: '番剧',
      type: '校园',
      tag: '限免',
      tagType: "2",
      episodes: '24',
      status: '2',
      score: '9.7',
    ),
    AnimateHotItem(
      coverUrl: './images/1.jpg',
      title: '奇幻世界舅舅',
      subTitle: '站内高分番剧',
      partition: '番剧',
      type: '漫画改',
      tag: '独播',
      tagType: "0",
      episodes: '13',
      status: '2',
      score: '9.8',
    ),
    AnimateHotItem(
      coverUrl: './images/3.jpg',
      title: '永生',
      subTitle: '仙魔双修，唯我独尊',
      partition: '国创',
      type: '小说改',
      tag: '出品',
      tagType: "1",
      episodes: '39',
      status: '1',
      score: '8.6',
    ),
  ],
  // --------------------
  [
    AnimateRankingItem(
      title: '热门番剧榜',
      list: [
        AnimateHotItem(
          coverUrl: './images/1.jpg',
          title: '鬼灭之刃 柱训练篇',
          subTitle: '羁绊连结，传承信念',
          partition: '番剧',
          type: '奇幻',
          tag: '会员',
          tagType: "3",
          episodes: '4',
          status: '1',
          score: '9.7',
        ),
        AnimateHotItem(
          coverUrl: './images/2.jpg',
          title: '不时用俄语小声说真心话的领桌艾莉同学',
          subTitle: '俄语传情真真切切',
          partition: '番剧',
          type: '小说改',
          tag: '独播',
          tagType: "0",
          episodes: '2',
          status: '1',
          score: '9.6',
        ),
        AnimateHotItem(
          coverUrl: './images/3.jpg',
          title: '亚托莉-我挚爱的时光-',
          subTitle: '暗流涌动的海边日常',
          partition: '番剧',
          type: '游戏改',
          tag: '出品',
          tagType: "1",
          episodes: '1',
          status: '1',
          score: '0',
        ),
        AnimateHotItem(
          coverUrl: './images/1.jpg',
          title: '怪兽8号',
          subTitle: '怪兽来袭，战力爆表',
          partition: '番剧',
          type: '漫画改',
          tag: '会员',
          tagType: "3",
          episodes: '12',
          status: '2',
          score: '8.7',
        ),
        AnimateHotItem(
          coverUrl: './images/2.jpg',
          title: '亚刻奥特曼',
          subTitle: '释放你的想象力',
          partition: '番剧',
          type: '特摄',
          tag: '会员',
          tagType: "3",
          episodes: '3',
          status: '1',
          score: '9.7',
        ),
        AnimateHotItem(
          coverUrl: './images/3.jpg',
          title: '魔法少女与邪恶曾经敌对。',
          subTitle: '正邪双方的甜蜜交锋',
          partition: '番剧',
          type: '漫画改',
          tag: '独播',
          tagType: "0",
          episodes: '2',
          status: '1',
          score: '0',
        ),
        AnimateHotItem(
          coverUrl: './images/1.jpg',
          title: '鬼灭之刃',
          subTitle: '谁都斩不断的羁绊',
          partition: '番剧',
          type: '漫画改',
          tag: '独播',
          tagType: "0",
          episodes: '26',
          status: '2',
          score: '9.7',
        ),
        AnimateHotItem(
          coverUrl: './images/2.jpg',
          title: '蜡笔小新 第八季（中文）',
          subTitle: '无限快乐蜡笔小新',
          partition: '番剧',
          type: '搞笑',
          tag: '会员',
          tagType: "3",
          episodes: '36',
          status: '1',
          score: '9.7',
        ),
        AnimateHotItem(
          coverUrl: './images/3.jpg',
          title: '鬼灭之刃 刀匠村篇',
          subTitle: '信念锻刀，斩尽恶鬼',
          partition: '番剧',
          type: '漫画改',
          tag: '独播',
          tagType: "0",
          episodes: '13',
          status: '2',
          score: '9.2',
        ),
        AnimateHotItem(
          coverUrl: './images/1.jpg',
          title: '地下城里的人们',
          subTitle: '我在迷宫当管理员',
          partition: '番剧',
          type: '漫画改',
          tag: '独播',
          tagType: "0",
          episodes: '2',
          status: '1',
          score: '0',
        ),
        AnimateHotItem(
          coverUrl: './images/2.jpg',
          title: '铁甲小宝 重置版 中文配音',
          subTitle: '童年经典回归！',
          partition: '番剧',
          type: '原创',
          tag: '会员',
          tagType: "3",
          episodes: '32',
          status: '1',
          score: '9.6',
        ),
        AnimateHotItem(
          coverUrl: './images/3.jpg',
          title: '百变的七仓同学',
          subTitle: '独自一人的戏精女王',
          partition: '番剧',
          type: '原创',
          tag: '出品',
          tagType: "1",
          episodes: '2',
          status: '1',
          score: '0',
        ),
        AnimateHotItem(
          coverUrl: './images/1.jpg',
          title: '鬼灭之刃 游郭篇',
          subTitle: '斩断鬼所栖身之夜',
          partition: '番剧',
          type: '漫画改',
          tag: '独播',
          tagType: "0",
          episodes: '11',
          status: '2',
          score: '9.7',
        ),
        AnimateHotItem(
          coverUrl: './images/2.jpg',
          title: '亦叶亦花',
          subTitle: '夏日校园青春物语',
          partition: '番剧',
          type: '原创',
          tag: '独播',
          tagType: "0",
          episodes: '2',
          status: '1',
          score: '0',
        ),
        AnimateHotItem(
          coverUrl: './images/3.jpg',
          title: 'X特遣队的奇幻之旅',
          subTitle: '小丑女上演奇幻冒险',
          partition: '番剧',
          type: '原创',
          tag: '独播',
          tagType: "0",
          episodes: '5',
          status: '1',
          score: '9.1',
        ),
        AnimateHotItem(
          coverUrl: './images/1.jpg',
          title: '葬送的芙莉莲',
          subTitle: '花海盛开，故人归来',
          partition: '番剧',
          type: '漫画改',
          tag: '会员',
          tagType: "3",
          episodes: '28',
          status: '2',
          score: '9.9',
        ),
        AnimateHotItem(
          coverUrl: './images/2.jpg',
          title: '新世界之门',
          subTitle: '结束了，还没有结束',
          partition: '番剧',
          type: '小说改',
          tag: '会员',
          tagType: "3",
          episodes: '4',
          status: '1',
          score: '0',
        ),
        AnimateHotItem(
          coverUrl: './images/3.jpg',
          title: '事与愿违的不死冒险者',
          subTitle: '重生为魔物的冒险',
          partition: '番剧',
          type: '小说改',
          tag: '会员',
          tagType: "3",
          episodes: '4',
          status: '1',
          score: '9.7',
        ),
        AnimateHotItem(
          coverUrl: './images/1.jpg',
          title: '齐木楠雄的灾难（日播&精选版）',
          subTitle: '超能同学竟在我身边',
          partition: '番剧',
          type: '泡面',
          tag: '会员',
          tagType: "3",
          episodes: '120',
          status: '2',
          score: '9.7',
        ),
        AnimateHotItem(
          coverUrl: './images/2.jpg',
          title: '咒术回战 第二季',
          subTitle: '天上天下，唯我独尊',
          partition: '番剧',
          type: '漫画改',
          tag: '会员',
          tagType: "3",
          episodes: '23',
          status: '2',
          score: '9.4',
        ),
      ],
    ),
    AnimateHotItem(
      coverUrl: './images/1.jpg',
      title: '中二病也要谈恋爱',
      subTitle: '站内高分番剧',
      partition: '番剧',
      type: '校园',
      tag: '独播',
      tagType: "0",
      episodes: '13',
      status: '2',
      score: '9.8',
    ),
    AnimateHotItem(
      coverUrl: './images/2.jpg',
      title: '男子高中生的日常',
      subTitle: '站内高分番剧',
      partition: '番剧',
      type: '搞笑',
      tag: '',
      tagType: null,
      episodes: '12',
      status: '2',
      score: '9.8',
    ),
    AnimateHotItem(
      coverUrl: './images/3.jpg',
      title: '物理魔法使-马修-',
      subTitle: '肌肉粉碎所有魔法',
      partition: '番剧',
      type: '漫画改',
      tag: '独播',
      tagType: "0",
      episodes: '12',
      status: '2',
      score: '8.6',
    ),
    AnimateHotItem(
      coverUrl: './images/1.jpg',
      title: '总之就是非常可爱 第二季',
      subTitle: '总之就是非常酸甜',
      partition: '番剧',
      type: '漫画改',
      tag: '独播',
      tagType: "0",
      episodes: '16',
      status: '2',
      score: '9.5',
    ),
    AnimateHotItem(
      coverUrl: './images/2.jpg',
      title: '在魔王城说晚安',
      subTitle: '为了不睡觉不择手段',
      partition: '番剧',
      type: '漫画改',
      tag: '会员',
      tagType: "3",
      episodes: '12',
      status: '2',
      score: '9.7',
    ),
    AnimateHotItem(
      coverUrl: './images/3.jpg',
      title: '邪神与厨二病少女',
      subTitle: '到底谁才是恶魔啊',
      partition: '番剧',
      type: '搞笑',
      tag: '独播',
      tagType: "0",
      episodes: '13',
      status: '2',
      score: '9.5',
    ),
  ],
];

List<dynamic> initList() {
  List resList = [];
  // 每个分页列表 pageData
  for (List pageData in list) {
    List pageList = [];
    if (pageData.length > 1) {
      // 取第一个为卡片或榜单
      // 剩余最多6个为列表
      pageList.add(pageData[0]);
      pageList.add(pageData.sublist(1, 7));
    }
    resList.addAll(pageList);
  }
  return resList;
}

class AnimateWidget extends StatelessWidget {
  const AnimateWidget({super.key});
  @override
  Widget build(BuildContext context) {
    return CustomScrollView(
      controller: NestedInnerScrollController.maybeOf(context),
      slivers: [
        // 处理嵌套遮挡问题
        SliverOverlapInjector(
          handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
        ),
        AnimateSwiper(),
        AnimateMenu(),
        const AnimateVipBar(),
        AnimateWatching(),
        const AnimateTypeBar('正在热播'),
        AnimateHot(
          list: hotList,
        ),
        AnimateComingSoon(),
        const AnimateTypeBar('猜你喜欢'),
        // 猜你喜欢的列表是每7个一页，第一个为大卡片或榜单，后6个组成小卡片列表
        ...(initList().map((e) {
          if (e is AnimateRankingItem) {
            return SliverToBoxAdapter(child: AnimateRank(e));
          } else if (e is AnimateHotItem) {
            return SliverToBoxAdapter(child: AnimateCard2(e));
          } else if (e is List) {
            return AnimateHot(list: e);
          } else
            // ignore: curly_braces_in_flow_control_structures
            return const SliverToBoxAdapter(child: SizedBox.shrink());
        }).toList()),
        // AnimateHot(),
        const SliverToBoxAdapter(child: SizedBox(height: 200)),
      ],
    );
  }
}

// ignore: must_be_immutable
class AnimateTypeBar extends StatelessWidget {
  final String title;
  const AnimateTypeBar(this.title, {super.key});
  @override
  Widget build(BuildContext context) {
    return SliverToBoxAdapter(
        child: Padding(
      padding: const EdgeInsets.only(left: 4, right: 4, top: 16),
      child: Text(title),
    ));
  }
}
